package cc.rengu.redp.bizimpl.upmp.service.impl;/*
package cc.rengu.redp.bizimpl.upmp.service.impl;

import cc.rengu.redp.bizimpl.upmp.common.BusinessContainer;
import cc.rengu.redp.bizimpl.upmp.dao.TermBrandInfoMapper;
import cc.rengu.redp.bizimpl.upmp.domain.TermBrandInfo;
import cc.rengu.redp.bizimpl.upmp.domain.TermBrandInfo;
import cc.rengu.redp.bizimpl.upmp.service.ITermBrandInfoService;
import cc.rengu.redp.bizimpl.upmp.service.IUpmpSysParamService;
import cc.rengu.redp.bizimpl.upmp.vo.UpmpUserInfoVO;
import cc.rengu.redp.bizimpl.utils.Common;
import cc.rengu.redp.bizimpl.utils.CommonUtils;
import cc.rengu.redp.bizimpl.utils.GZIPUtils;
import cc.rengu.redp.common.domain.QueryRequest;
import cc.rengu.redp.common.utils.SortUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageImpl;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

*/
/**
 * @author 刘玉亮.LL
 *//*

@Service
public class TermBrandInfoServiceImpl extends ServiceImpl<TermBrandInfoMapper, TermBrandInfo> implements ITermBrandInfoService {

    @Autowired
    IUpmpSysParamService upmpSysParamService;

    @Override
    public Map<String,Object> termbrandSelect2List(QueryRequest request,String q){
        LambdaQueryWrapper<TermBrandInfo> queryWrapper = new LambdaQueryWrapper<>();
        q=q.replaceAll("&amp;", "&");
        String[] param = q.split("&");
         UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);

        if(null!=param&&param.length>0){
            queryWrapper.or(qw -> qw.likeRight(TermBrandInfo::getBrandCode, param[0])
                    .likeRight(TermBrandInfo::getBrandName, param[0]));
        }
        queryWrapper.eq(TermBrandInfo::getStatus, "01");
        if(user.isAdmin()) {
            queryWrapper.eq(TermBrandInfo::getInstId, param[1]);
        }else{
//            queryWrapper.in(TermBrandInfo::getCrtOrgId, GZIPUtils.uncompressToString(user.getUserOrgCodes()));
        }
        */
/*构建pageable时需要放入request里面的参数
        "rows"-每页多少行
        "page"-当前页
        "start"-起始行 ，可以不提供，默认为page*rows
        *//*

       Page<TermBrandInfo> page = new Page<>();
        SortUtil.handlePageSort(request, page, true);
        Page<TermBrandInfo> page1 = this.page(page, queryWrapper);
        List<TermBrandInfo> listx = page1.getRecords();
        Map<String,Object> maps = new HashMap<String,Object>();
        Map<String, String> map = new HashMap<String,String>();
        List<Object> list = new ArrayList<Object>();
        if (listx != null) {
            for(int i=0;i<listx.size();i++){
                TermBrandInfo tb = listx.get(i);
                map = new HashMap<String,String>();
                map.put("id",tb.getBrandCode());
                map.put("name",tb.getBrandName());
                map.put("desc",tb.getBrandDesc());

                list.add(map);
            }
            maps.put("results", list);
            int pageIndex = Common.isBlank(request.getPageNum()) ? 1 : request.getPageNum();
            if (pageIndex == page1.getTotal()) {
                maps.put("more", false);
            }else{
                maps.put("more", true);
            }
        }
        return maps;
    }

    @Override
    public List<String> findAllbrandCd() {
        // TODO Auto-generated method stub
        return this.baseMapper.findAllbrandCd();
    }
    @Override
    public List<String> findAllbrandName(String brandcd) {
        // TODO Auto-generated method stub
        return this.baseMapper.findAllbrandName(brandcd);
    }
    @Override
    public List<String> findAllbrandName() {
        // TODO Auto-generated method stub
        return this.baseMapper.findAllbrandName();
    }
    @Override
    public TermBrandInfo findTermBrand(String brandcd) {
        // TODO Auto-generated method stub
        return this.baseMapper.findbrandCd(brandcd);
    }

    */
/**
     * 查询终端品牌及终端品牌下的型号数量
     * @param request
     * @param model
     * @return
     *//*

    public Page<Map> termbrandSelectList(HttpServletRequest request, Model model) {
        Page<Map> page;
        String defaultRows = request.getParameter(BusinessContainer.ECP_DEFAULTROWS_PARA_NAME);
        if(StringUtils.isBlank(defaultRows))defaultRows = BusinessContainer.ECP_PAGE_DEFAULTROWS;
        Pageable pageable = PropertyFilter.buildPageableFromHttpRequest(request,Integer.parseInt(defaultRows));

         UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        StringBuffer param = new StringBuffer();
        String userOrgCodes = GZIPUtils.uncompressToString(user.getUserOrgCodes());
        String status=BusinessContainer.status_00;
        String reqparam = request.getParameter("search['CN_brandCd_OR_brandName_OR_brandDesc']");
        if(!StringUtils.isBlank(reqparam)){
            param.append(" and (a.BRAND_CODE like '%"+reqparam+"%' or a.BRAND_NAME  like '%"+reqparam+"%' or a.BRAND_DESC  like '%"+reqparam+"%' ) ");
        }
        StringBuffer sql = new StringBuffer();
        sql.append("\n" +
                "select count(b.brand_code) as XHSL,a.id as id,a.inst_id as instId, a.brand_code as brandcd,a.brand_name as brandname,a.brand_desc as branddesc,a.contact_name as contactname, a.contact_phone as contactphone, a.contact_email as contactemail, a.audit_refuse_reason, a.status,a.audit_status, a.crt_org_id,a.opr_id,a.create_time, a.last_opr_id, a.last_update_time,a.create_time,a.last_audit_time,a.last_audit_id\n" +
                "from T_B_TERM_BRAND_INFO a\n" +
                "left join t_b_term_model_info b on a.brand_code = b.brand_code and b.status=01\n" +
                "group by b.brand_code, a.id,a.inst_id, a.brand_code,a.brand_name,a.brand_desc,a.contact_name, a.contact_phone, a.contact_email, a.audit_refuse_reason, a.status,a.audit_status, a.crt_org_id,a.opr_id,a.create_time, a.last_opr_id, a.last_update_time,a.create_time,a.last_audit_time,a.last_audit_id\n" +
                "having a.status=01");
        try{
            if(StringUtils.isNotBlank(sql)){
                sql.append(param);
                log.debug("终端品牌列表数据加载查询SQL"+sql.toString());
                Query query = this.getEntityManager().createNativeQuery(sql.toString());
                ((SQLQuery)query.unwrap(SQLQuery.class)).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);


                Object count = query.getResultList().size();

                List<Map<String, String>> termbrand =query.getResultList();
                DataDict parent = dataDictDao.findByPrimaryKey(ShiroJdbcRealm.SYS_INST_PARAM);
                List<DataDict> datadict =dataDictDao.findEnabledChildrenByParent(parent);//instid当key取value
                query.setFirstResult(pageable.getOffset()).setMaxResults(pageable.getPageSize());
                List list=new ArrayList();
                for(Map<String, String> c:termbrand){
                    DataDict d=new DataDict();
                    d.setPrimaryKey(DictUtils.IGAS_DEFAULT_INST_ID);
                    datadict.add(d);
                    for(DataDict cc:datadict){
                        if(c.get("INSTID").equals(cc.getPrimaryKey())){
                            c.put("instname",cc.getPrimaryValue());

                        }
                    }
                    list.add(c);
                }

                page = new PageImpl<>(list, pageable, Long.valueOf(count.toString()).longValue());

//		    	page = this.findByPageNativeSQL(pageable, sql.toString());
                model.addAttribute("pageData", page);
                model.addAttribute("error","");
            }else{
                model.addAttribute("error","");
                page = new PageImpl<>(new java.util.ArrayList<Map>(), pageable, 0);
                model.addAttribute("pageData", page);
            }
        }catch(Exception e){
            model.addAttribute("error", "sql异常,请检查sql语句的正确性!");
            page = new PageImpl<>(new java.util.ArrayList<Map>(), pageable, 0);

            model.addAttribute("pageData", page);
            log.error(e.getMessage());
        }
        return page;
    }
}
*/
